﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for CCommon
/// </summary>
public class CCommon
{
	public CCommon()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public string Read(int id)
    {
        DataAccess d = new DataAccess();
        d.Open();
        Dictionary<object, object> pars = new Dictionary<object, object>();
        pars.Add("ID", id);
        DataTable dt = d.ExeDataTable("select * from common where id=@ID", pars);
        d.Close();
        if (null != dt)
        {
            return dt.Rows[0]["content"].ToString();
        }
        return null;
    }

    public DataTable ReadBySort(string sort)
    {
        DataAccess d = new DataAccess();
        d.Open();
        Dictionary<object, object> pars = new Dictionary<object, object>();
        pars.Add("Sort", sort);
        DataTable dt = d.ExeDataTable("select * from common where sort=@Sort", pars);
        d.Close();
        return dt;
    }

    public bool Update(int id, string content)
    {
        DataAccess d = new DataAccess();
        d.Open();
        Dictionary<object, object> pars = new Dictionary<object, object>();
        pars.Add("Content", content);
        pars.Add("ID", id);
        int c = d.ExeNonQuery("update common set content=@Content where id=@ID", pars);
        d.Close();
        if (c>0)
        {
            return true;
        }
        return false;
    }
}